function [result, Ir ] = character_Segmentation0( img, IS_DEBUG, FOLDER_RESULT,file_name )
%CHARACTER_SEGMENTATION Summary of this function goes here
%   Detailed explanation goes here

z = size(img,3);
if z==3
    img = rgb2gray(img);
end

maxwidth = 256;
img=imresize(img,[NaN maxwidth]);
if mode == 2
    xmin= 5;
    ymin= 0;
    [maxhigh, maxwidth] = size(img);
    width = maxwidth - 2*xmin;
    high = maxhigh-2*ymin;
    img = imcrop(img, [xmin ymin width high]);
elseif mode ==3
    xmin= 0;
    ymin= 5;
    [maxhigh, maxwidth] = size(img);
    width = maxwidth - 2*xmin;
    high = maxhigh-2*ymin;
    img = imcrop(img, [xmin ymin width high]);
end

% [Gmag, ~] = imgradient(img,'prewitt');

im1= medfilt2(img,[3 3]); %Median filtering the image to remove noise%
BW = edge(im1,'canny'); %finding edges
BW = bwmorph(BW,'bridge');
% BW = imdilate(BW);
msk=[0 0 0 0 ;
    0 1 1 0 ;
    0 1 1 0 ;
    0 0 0 0 ];
B=conv2(double(BW),double(msk),'same');
% B = removeEdge(B);
cc = bwconncomp(B,8);
fd =  regionprops(cc,'BoundingBox','Area');
result = {};
num = 1;
for i = 1:cc.NumObjects  
    width = fd(i).BoundingBox(3);
    high = fd(i).BoundingBox(4);
    area = fd(i).Area;
    if width > 3 && width<100 && high >32 && high < 100 && area > 200
        result{num} = imcrop(B, fd(i).BoundingBox);
        num = num + 1;
    end
end
if IS_DEBUG
    numCharacter = length(result);
    col = ceil(sqrt(numCharacter));
    row = ceil(numCharacter/col);
    figure(2);
    for i=1:numCharacter
        subplot(row, col, i);
        imshow(result{i});
    end
    
end
end

